package com.cloud.tsp.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cloud.api.domain.forward.QueryForwardDetail;
import com.cloud.api.domain.forward.VehicleForwardError;
import com.cloud.api.utils.ExcelUtils;
import com.cloud.mybatis.domain.TableDataInfo;
import com.cloud.tsp.mapper.VehicleForwardErrorMapper;
import com.cloud.tsp.service.IVehicleForwardErrorService;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Locale;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author haohaibo
 * @since 2024-01-30
 */
@Service("vehicleForwardErrorService")
public class VehicleForwardErrorServiceImpl extends ServiceImpl<VehicleForwardErrorMapper, VehicleForwardError> implements IVehicleForwardErrorService {

    @Resource
    private VehicleForwardErrorMapper vehicleForwardErrorMapper;
    @Resource
    private MessageSource messageSource;

    @Override
    public TableDataInfo<VehicleForwardError> selectForwardError(QueryForwardDetail para) {
        Page<VehicleForwardError> page = new Page<>();
        page.setCurrent(para.getPage());
        page.setSize(para.getPageSize());
        IPage<VehicleForwardError> data = vehicleForwardErrorMapper.selectForwardError(page, para);
        return TableDataInfo.build(data);
    }

    @Override
    public void exportForwardList(QueryForwardDetail para, HttpServletResponse response) throws IOException {
        Locale locale = LocaleContextHolder.getLocale();
        List<VehicleForwardError> list = vehicleForwardErrorMapper.selectForwardErrorList(para);
        String tableName = "table.forwardDetail";
        tableName = messageSource.getMessage(tableName, null, tableName, locale);
        ExcelUtils.export(response,tableName,list,VehicleForwardError.class);
    }
}